import { getMemberList } from '@/network/api/commonApi';
import { getApiDetail, getserveUnit, selBatchGroup } from '@/network/api/serviceunit'
import {
  applyPower,
  getDataType,
  // getMyRoleList,
  getDataDetail,//查看详情
  getDataTest,//连接测试
  getdataSoure,
  getApiSoure
} from '@/network/api/commonApi';


let initState = () => ({
  dataList: [],
  apiList: [],
  total: 0,//数据源数据总条数
  pageSize: 10,//数据源每页多少条
  pageNum: 1,//第几页
  apiTotal: 0,//api数据总条数
  apiPageSize: 10,//api每页多少条
  apiPageNum: 1,//api第几页
  addVisible: false,//控制模态框
  addVisibleModalType: 'dataSee', //弹出框类型
  allDataTypeList: [], //所有数据源类型
  apiDesc: [], //api描述修改
  // applyType: {
  //   box1: false,
  //   box2: false,
  // },//权限类型
  workSpaceName: [],
  dataPop: {},// 数据源弹窗数据
  testId: '',// 测试id
  apiPop: [],// api弹窗数据
  serveUnitName: ""// api详情 对应服务单元name
});

export default {
  namespace: 'MyRole',
  state: { ...initState() },
  effects: {
    // 数据源申请权限
    *applyPower({ payload }, { call, put }) {
      return yield call(applyPower, { body: payload });
    },
    // 查询数据源类型
    *getDataType({ payload }, { call, put }) {
      return yield call(getDataType);
    },
    // 查询所有工作空间名
    *getMemberList({ payload }, { call, put }) {
      return yield call(getMemberList);
    },

    // 获取所有数据源数据
    *getdataSoure({ payload }, { call, put }) {
      return yield call(getdataSoure, { params: payload });
    },
    // 数据源查看详情
    *getDataDetail({ payload }, { call, put }) {
      return yield call(getDataDetail, { params: payload });
    },

    // 获取api所有数据
    *getApiSoure({ payload }, { call, put }) {
      return yield call(getApiSoure, { params: payload });
    },
    // 测试链接
    *getDataTest({ payload }, { call, put }) {
      return yield call(getDataTest, { params: payload });
    },
    // api详情
    *getApiDetail({ payload }, { call, put }) {
      return yield call(getApiDetail, { params: payload });
    },
    // 获取服务单元名称
    *getServeUnits({ payload }, { call, put }) {
      return yield call(getserveUnit, { params: payload });
    },
    // api分组名称
    *selBatchGroup({ payload }, { call, put }) {
      return yield call(selBatchGroup, { body: payload });
    }
  },
  reducers: {
    setState(state, action) {
      return { ...state, ...action.payload };
    },
    init(state, action) {
      return { ...initState(), ...action.payload };
    },
  },
};
